package com.ruoyi.busi.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.busi.domain.vo.BusiCompanyGridVo;
import com.ruoyi.busi.domain.bo.BusiCompanyGridBo;
import com.ruoyi.busi.service.IBusiCompanyGridService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 排放因子Controller
 *
 * @author ruoyi
 * @date 2024-12-02
 */
@Validated
@Api(value = "排放因子控制器", tags = {"排放因子管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/busi/companyGrid")
public class BusiCompanyGridController extends BaseController {

    private final IBusiCompanyGridService iBusiCompanyGridService;

    /**
     * 查询排放因子列表
     */
    @ApiOperation("查询排放因子列表")
    @PreAuthorize("@ss.hasPermi('busi:companyGrid:list')")
    @GetMapping("/list")
    public TableDataInfo<BusiCompanyGridVo> list(@Validated(QueryGroup.class) BusiCompanyGridBo bo) {
        return iBusiCompanyGridService.queryPageList(bo);
    }

    /**
     * 导出排放因子列表
     */
    @ApiOperation("导出排放因子列表")
    @PreAuthorize("@ss.hasPermi('busi:companyGrid:export')")
    @Log(title = "排放因子", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated BusiCompanyGridBo bo, HttpServletResponse response) {
        List<BusiCompanyGridVo> list = iBusiCompanyGridService.queryList(bo);
        ExcelUtil.exportExcel(list, "排放因子", BusiCompanyGridVo.class, response);
    }

    /**
     * 获取排放因子详细信息
     */
    @ApiOperation("获取排放因子详细信息")
    @PreAuthorize("@ss.hasPermi('busi:companyGrid:query')")
    @GetMapping("/{id}")
    public AjaxResult<BusiCompanyGridVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iBusiCompanyGridService.queryById(id));
    }

    /**
     * 新增排放因子
     */
    @ApiOperation("新增排放因子")
    @PreAuthorize("@ss.hasPermi('busi:companyGrid:add')")
    @Log(title = "排放因子", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody BusiCompanyGridBo bo) {
        return toAjax(iBusiCompanyGridService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改排放因子
     */
    @ApiOperation("修改排放因子")
    @PreAuthorize("@ss.hasPermi('busi:companyGrid:edit')")
    @Log(title = "排放因子", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody BusiCompanyGridBo bo) {
        return toAjax(iBusiCompanyGridService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除排放因子
     */
    @ApiOperation("删除排放因子")
    @PreAuthorize("@ss.hasPermi('busi:companyGrid:remove')")
    @Log(title = "排放因子" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iBusiCompanyGridService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
